import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JFrame;


public class Listeners extends JFrame implements  ActionListener  {
	private GUI gui; //Stores the GUI that is passed in from the previous part
	private boolean running=false;
	private Server s;
	public Listeners(GUI g){
		gui=g;
	}

	public void actionPerformed(ActionEvent e) {
		running=!running;
		if (running){
			try {
				gui.btnpower.setText("Stop server");
				s= new Server(gui); //When the button is pressed, it will call the server class and pass in the GUI to it.

			} catch (IOException e1) {
				gui.txtresults.setText("Server failed to start");
				e1.printStackTrace();
			}
		}
		else{
			try {
				s.quit();
				gui.txtresults.append("Server has shut down ...\n");
				gui.btnpower.setText("Start server");
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
}